1 =============================================================================
2 SILVERLIGHT APPLICATION : CSSL4MEF Project Overview
3 =============================================================================
5 /////////////////////////////////////////////////////////////////////////////
8 Managed Extensibility Framework (MEF) is a framework which could assist
9 developers to design extensible application. It's supported by Silverlight 4.
10 This sample uses MEF to create a simple text formater. By using the
11 predefined contract, users can create components to enhance the formater's
12 functionality. The components can be loaded at runtime.
15 /////////////////////////////////////////////////////////////////////////////
19 1. Open CSSL4MEF solution and build the solution.
20 2. Right click CSSL4MEFTestPage.aspx file, select "View in Browser".
21 3. In opened page, you may find a Silverlight application.
22 a. In right area of Silverlight, there are some controls which cloud change
23 the state of text shown on left side. For each controls in right area, it's
24 composed with application by MEF.
25 b. By Clicking the "Click to load color config control" button, MEF would load
26 extension component and recompose the config panel dynamicly.
29 /////////////////////////////////////////////////////////////////////////////
32 Silverlight 4 Tools for Visual Studio 2010
33 http://www.silverlight.net/getstarted/
36 http://www.silverlight.net/getstarted/
39 /////////////////////////////////////////////////////////////////////////////
42 1. How to use MEF to build an extensible Silverlight Application?
43 It's a long story, I recommend CodeBetter's blog MEF series
44 http://codebetter.com/blogs/glenn.block/archive/2009/11/30/building-the-hello-mef-dashboard-in-silverlight-4-part-i.aspx
46 2. What's the solution structure?
47 CSSL4MEF project utilized MEF to implement the ConfigPanel control, which cloud
48 download plugin xap and extend functionality at runtime.
50 CSSL4MEF.Web project is CSSL4MEF silverlight application's host web application.
52 ConfigControl.Contract project defines the contract as the ConfigPanel's extension
55 ConfigControl.Extension project implement configpanel's extension interface, create
56 a components "ColorPicker".
58 3. How does MEF work in this project?
59 When running the application, you may see there are mainly two regions on
60 view. The left side shows a short text, and the right side has certain
61 controls which could change text style. Actually, these controls are binded to a
62 predefined DataModel. Those styled text has no magical, just bind UI property
63 to datamodel and utilize INotifiyPropertyChanged to update UI in realtime.
64 For right side, it is a Silverlight control "ConfigPanel". It could
65 bind to datamodel by "ConfigData" property, and generate config controls
68 Because the datamodel's property can be any type and has various requirement,
69 To make the ConfigPanel be able to generate appropriate controls for any
70 datamodels, we need to let the ConfigPanel be extensible. In this scenario,
71 MEF could help to meet this desgin task.
73 We defined an interface called "IConfigControl", which should be able to
74 return an edit control binded to the given property field. The ConfigPanel
75 utilze MEF to hold a list of IConfigControl, by calling
76 IConfigControl.MatchTest method, configPanel would find most suitable
77 configControl for each property and add control to config panel.
79 Suppose we have a datamodel, which has Color type property, to extend
80 the ConfigPanel to support Color type, we would create a new silverlight
81 project, implementing IConfigControl and mark with Export attribute to
82 make it discoverable. Then, by using "DeploymentCatalogService", we could
83 dynamicly load the extension config control, once the calagory changed,
84 configPanel get notificaton and recompose UI for datamodel.
87 /////////////////////////////////////////////////////////////////////////////
91 http://mef.codeplex.com/
94 /////////////////////////////////////////////////////////////////////////////